//
//  YKTabBarController.m
//  YingKe
//
//  Created by 崔博 on 16/11/19.
//  Copyright © 2016年 崔博. All rights reserved.
//

#import "YKTabBarController.h"
#import "YKTabBar.h"
#import "YKBaseNavController.h"
@interface YKTabBarController ()<YKTabBarDelegate>
@property (nonatomic ,strong) YKTabBar *ykTabbar;
@end

@implementation YKTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 配置控制器
    [self configViewControllers];
    // 加载tabbar
    [self.tabBar addSubview:self.ykTabbar];
    self.view.backgroundColor = [UIColor redColor];
    // 解决tabbar的阴影线
    [[UITabBar appearance] setShadowImage:[UIImage new]];
    [[UITabBar appearance] setBackgroundImage:[UIImage new]];
}
#pragma mark - delegate
#pragma mark tabbarDelegate
- (void)tabbar:(YKTabBar *)tabbar seletexIndex:(YKItemType)index
{
    if (index != YKItemTypeLaunch) {
        self.selectedIndex = index - YKItemTypeLive;
        return;
    }
}
#pragma mark - event
#pragma mark  configViewControllers
- (void)configViewControllers
{
    NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"STLimitController",@"STMenuController",@"STShoppingController",@"STMeController"]];
    NSArray *titleArray = @[@"限时购",@"分类",@"购物车",@"我的"];
    for (NSInteger i = 0; i < array.count; i ++) {
        NSString *vcName = array[i];
        UIViewController *vc = [[NSClassFromString(vcName) alloc] init];
        vc.title = titleArray[i];
        YKBaseNavController *nav = [[YKBaseNavController alloc] initWithRootViewController:vc];
        [array replaceObjectAtIndex:i withObject:nav];
    };
    self.viewControllers = array;
}

#pragma mark - lazy
- (YKTabBar *)ykTabbar
{
    if (!_ykTabbar) {
        _ykTabbar = [[YKTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 49)];
        _ykTabbar.delegate = self;
    }
    return _ykTabbar;
}

@end
